﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Background.Core.Entity;
using Commons.Entity.CommonEnums;
using Commons.Entity;
using System.Linq.Expressions;
namespace Background.Core.DAL
{
    public class WebManageUsersRepository : BackgroundRepositoryBase
    {
        /// <summary>
        /// 用戶登陸
        /// </summary>
        /// <param name="webManageUsers"></param>
        /// <returns></returns>
        public WebManageUsers UserLogin(WebManageUsers webManageUsers)
        {
            WebManageUsers linq = this.GetEntities<WebManageUsers>().Where(i =>
               i.LoginName == webManageUsers.LoginName
              && i.Password == webManageUsers.Password
              && i.Status == (int)Status.Normal).FirstOrDefault();
            return linq;
        }
        /// <summary>
        /// 得到后台用户列表
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="pp"></param>
        /// <returns></returns>
        public PagedList<WebManageUsers> GetWebManageUsers(
            Expression<Func<WebManageUsers, bool>> predicate,
            PagingParam pp)
        {
            var linq = base.GetEntities<WebManageUsers>();
            if (predicate != null)
                linq = linq.Where(predicate);
            return linq.ToPagedList(pp.PageIndex, pp.PageSize);
        }
    }
}